package com.example.hdwx.myapplication.base_activity;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.example.hdwx.myapplication.R;

/**
 * 设置界面
 */
public class SetUp_Activity extends AppCompatActivity {

    LinearLayout wipeCache;
    FrameLayout open,shut;
    LinearLayout region,language,update,about;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_up);
        wipeCache = (LinearLayout) findViewById(R.id.setup_activity_linearLayout1);
        open = (FrameLayout) findViewById(R.id.setup_activity_frameLayout1);
        shut = (FrameLayout) findViewById(R.id.setup_activity_frameLayout2);
        region = (LinearLayout) findViewById(R.id.setup_activity_linearLayout2);
        language = (LinearLayout) findViewById(R.id.setup_activity_linearLayout3);
        update = (LinearLayout) findViewById(R.id.setup_activity_linearLayout4);
        about = (LinearLayout) findViewById(R.id.setup_activity_linearLayout5);
        button = (Button) findViewById(R.id.setup_activity_button);

        init();
    }

    private void init() {
        
        wipeCache.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //// TODO: 17-2-17  弹出提示框
                final AlertDialog.Builder builder = new AlertDialog.Builder(SetUp_Activity.this);
                //设置对话框标题
                builder.setTitle("提示");
                //设置对话框的内容
                builder.setMessage("是否清空缓存？");
                //设置确定按钮
                builder.setPositiveButton("清空", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //// TODO: 17-2-17 执行清空缓存
                        //控制对话框消失
                        builder.create().dismiss();
                    }
                });
                //设置取消按钮
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //控制对话框消失
                        builder.create().dismiss();
                    }
                });
                //点击对话框以外的区域，对话框不消失
                builder.create().setCanceledOnTouchOutside(true);
                //显示对话框
                builder.create().show();
            }
        });
        
        open.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                open.setVisibility(View.GONE);
                shut.setVisibility(View.VISIBLE);
            }
        });
        shut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shut.setVisibility(View.GONE);
                open.setVisibility(View.VISIBLE);
            }
        });
        
        region.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //// TODO: 17-2-17 区域地区选中 
            }
        });
        
        language.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //// TODO: 17-2-17 语言选择 
            }
        });
        
        update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //// TODO: 17-2-17 点击执行更新 并判断 
            }
        });
        
        about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //// TODO: 17-2-17 跳转到关于日日煮页面 
            }
        });

        if (false){//// TODO: 17-2-17 判断未登陆就隐藏该控件
            button.setVisibility(View.GONE);
        }

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //// TODO: 17-2-17 取消登陆状态
            }
        });
    }

    public void revert(View view) {
        finish();//结束当前界面(返回)
    }

}
